package com.itxiaoxiong.chat.service.impl;

import com.itxiaoxiong.chat.mapper.GroupMapper;
import com.itxiaoxiong.chat.pojo.GroupMembers;
import com.itxiaoxiong.chat.pojo.GroupMessages;
import com.itxiaoxiong.chat.pojo.Groups;
import com.itxiaoxiong.chat.pojo.Result;
import com.itxiaoxiong.chat.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class GroupServiceImpl implements GroupService {

    @Autowired
    private GroupMapper groupMapper;

    /*
    根据用户id查找所在群列表
     */
    @Override
    public List<GroupMembers> getGroups(Integer userId) {
        return groupMapper.getGroupById(userId);
    }

    /*
    根据群聊id查找群的聊天记录
     */
    @Override
    public List<GroupMessages> groupChatSelect(Integer groupId) {
        return groupMapper.groupChatSelect(groupId);
    }

    /*
    发消息
     */
    @Override
    public void groupAddChat(GroupMessages groupMessages) {
        groupMessages.setSendTime(LocalDateTime.now());
        groupMapper.groupAddChat(groupMessages);
    }

    /*
    根据群名查群
     */
    @Override
    public Groups groupByname(String groupName) {
        return groupMapper.groupName(groupName);
    }

    /*
    加群
     */
    @Override
    public void groupAdd(GroupMembers groupMembers) {
        groupMapper.groupAdd(groupMembers);
    }

    /*
    退群
     */
    @Override
    public void groupDelete(GroupMembers groupMembers) {
       groupMapper.groupDelete(groupMembers);
    }

    /*
    发文件
     */
    @Override
    public void addGroupFile(GroupMessages groupMessages) {
        groupMessages.setSendTime(LocalDateTime.now());
        groupMapper.addGroupFile(groupMessages);
    }

    /*
    查找群成员
     */
    @Override
    public List<Integer> getMemberByGroupId(Integer groupId) {
        List<Integer> member = groupMapper.getMemberByGroupId(groupId);
        return member;
    }
}
